<%--
  Created by IntelliJ IDEA.
  User: qiliping
  Date: 15/12/14
  Time: 下午5:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>添加资讯</title>

</head>
<body>
<div class="row">
    <div class="col-md-12">
        <!-- BEGIN PAGE TITLE & BREADCRUMB-->
        <h3 class="page-title">
            资讯管理 <small>添加资讯</small>
        </h3>
        <ul class="page-breadcrumb breadcrumb">
            <li><i class="fa fa-home"></i> <a href="${ctx}"> 首页 </a> <i
                    class="fa fa-angle-right"></i></li>
            <li><a href="${ctx}/news"> 资讯管理 </a> <i
                    class="fa fa-angle-right"></i></li>
            <li><a href="#"> 添加资讯 </a></li>
        </ul>
        <!-- END PAGE TITLE & BREADCRUMB-->
    </div>
</div>
<!-- END PAGE HEADER-->
<!------内容区---->
<div class="main">

    <div class="row">
        <div class="col-md-12">
            <form:form modelAttribute="NewsAddModel" method="post" class="form-horizontal">

                <div class="form-group">
                    <label class="control-label col-md-3">标题：</label>
                    <div class="col-md-4">
                        <form:input path="title" cssClass="form-control" maxlength="40" placeholder=""></form:input>
                    </div>
                    <form:errors path="title" cssClass="field-validation-error" element="div"></form:errors>
                </div>
                <div class="form-group">
                    <label class="control-label col-md-3">所属分类：</label>
                    <div class="col-md-2">
                        <form:select path="categoryId" cssClass="form-control js-roleSelect">
                            <option value="">请选择</option>
                            <form:options items="${categoryList}" itemLabel="categoryName" itemValue="categoryId" />
                        </form:select>

                    </div>
                    <form:errors path="categoryId" cssClass="field-validation-error" element="div"></form:errors>
                </div>
                <div class="form-group">
                    <label class="control-label col-md-3">来源：</label>
                    <div class="col-md-4">
                        <form:input path="origin" cssClass="form-control" maxlength="10" placeholder=""></form:input>
                    </div>
                </div>
                <div class="form-group">
                    <label class="control-label col-md-3">图片：</label>
                    <div class="col-md-4">
                        <img alt="" id="aimg" src="" width="100px" height="100px" />
                        <form:hidden path="image" id="image"/>
                        <input id="image3" type="button" value="上传图片" />
                    </div>
                </div>

                <div class="form-group">
                    <label class="control-label col-md-3">简要介绍：</label>
                    <div class="col-md-8">
                        <form:textarea path="summary" cssClass="form-control" cssStyle="width: 75%; height: 120px;"></form:textarea>
                    </div>
                </div>
                <div class="form-group">
                    <label class="control-label col-md-3">内容：</label>
                    <div class="col-md-8">
                        <form:textarea path="content" cssClass="form-control" cssStyle="width: 100%; height: 400px;"></form:textarea>
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-md-9 col-md-offset-3">
                        <button type="submit" class="btn blue">添加</button>
                        <span class="field-validation-error">${error}</span>
                    </div>
                </div>
            </form:form>
        </div>
    </div>

</div>
<myfooter>
    <script>
        var editor;
        KindEditor.ready(function(K) {
            editor = K.create('textarea[name="content"]', {
                allowFileManager : true
            });

            var uploadbutton = K.uploadbutton({
                button : K('#image3')[0],
                fieldName : 'imgFile',
                url : '${ctx}/file_upload?dir=image',
                afterUpload : function(data) {
                    if (data.error === 0) {
                        var url = K.formatUrl(data.url, 'absolute');
                        aimg
                        K('#aimg').attr("src", url);
                        K('#image').val(url);
                    } else {
                        alert(data.message);
                    }
                },
                afterError : function(str) {
                    alert('自定义错误信息: ' + str);
                }
            });
            uploadbutton.fileBox.change(function(e) {
                uploadbutton.submit();
            });
        });
    </script>
</myfooter>
</body>
</html>
